package com.lingyuan.product.controller;

import com.lingyuan.common.core.domain.R;
import com.lingyuan.common.core.domain.vo.pms.SpuOrderItemVo;
import com.lingyuan.common.core.exception.ServiceException;
import com.lingyuan.product.domain.vo.SpuVo;
import com.lingyuan.product.domain.vo.WareSkuStock;
import com.lingyuan.product.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SpuController
 * @Description 描述
 * @Author guoxin
 * @Date 2024/9/19 19:01
 */
@RestController
@RequestMapping("/spu")
public class SpuController {
    @Autowired
    private SpuService spuService;
    /**
     * 添加商品
     */
    @PostMapping("/addProduct")
    public R addSpuInfo(@RequestBody @Validated SpuVo spuVo){
        if (null == spuVo){
            throw new ServiceException("参数为空");
        }
        spuService.addSpuInfo(spuVo);
        return R.ok("添加成功");
    }
    /**
     * 修改商品
     */
    @PostMapping("/updSpuProduct")
    public R updProduct(@RequestBody SpuVo spuVo){
        if (null == spuVo){
            throw new ServiceException("参数为空");
        }
        spuService.updproduct(spuVo);
        return R.ok("修改成功");
    }
    /**
     * 上架商品
     */
    @PostMapping("/grounding/{spuId}")
    public R groundIng(@PathVariable("spuId") Long spuId){
        spuService.groupIng(spuId);
        return R.ok("上架成功");
    }
    /**
     * 下架商品
     */
    @DeleteMapping("/delete/{spuId}")
    public R deleteSpuId(@PathVariable("spuId") Long spuId){
        spuService.deleteSpuId(spuId);
        return R.ok("下架成功");
    }
    /**
     * 设置库存
     */
    @PostMapping("/addStock")
    public R addStock(@RequestBody WareSkuStock wareSkuStock){
        spuService.addStock(wareSkuStock);
        return R.ok("设置成功");
    }

    /* *
     * @Title: findBySkuIdSpuInfo
     * @Author: DELL
     * @Date: 2024-09-24 11:53:50
     * @Params: [skuId]
     * @Return: R<SpuOrderItemVo>
     * @Description: 根据skuId查询spu信息
     */

    /**
     * 根据skuId查询spu信息
     * @param skuId
     * @return
     */
    @GetMapping("findBySkuIdSpuInfo/{skuId}")
    public R<SpuOrderItemVo> findBySkuIdSpuInfo(@PathVariable("skuId") Long skuId){
        SpuOrderItemVo spuOrderItemVo = spuService.findBySkuIdSpuInfo(skuId);
        return R.ok(spuOrderItemVo);
    }


}
